package com.WebMentorPro.system.service.impl;


import com.WebMentorPro.system.common.ErrorCode;
import com.WebMentorPro.system.exception.BusinessException;
import com.WebMentorPro.system.mapper.ExpertReadingMapper;
import com.WebMentorPro.system.model.dto.expertReading.ExpertQueryByMyRequest;
import com.WebMentorPro.system.model.dto.expertReading.ExpertQueryRequest;
import com.WebMentorPro.system.model.entity.ExpertReading;
import com.WebMentorPro.system.model.vo.ExpertReadingVO;
import com.WebMentorPro.system.service.ExpertReadingService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author bianxiaoyao
 * @description 针对表【expert_reading(大咖阅读表)】的数据库操作Service实现
 * @createDate 2024-11-24 11:24:42
 */
@Service
public class ExpertReadingServiceImpl extends ServiceImpl<ExpertReadingMapper, ExpertReading> implements ExpertReadingService {

    @Resource
    private ExpertReadingMapper expertReadingMapper;

    @Override
    public Page<ExpertReadingVO> getQueryWrapper(Page<ExpertReadingVO> pageParam, ExpertQueryRequest expertQueryRequest) {
        // 自定义分页查询
        List<ExpertReadingVO> expertReadingVOS = expertReadingMapper.getQuery(pageParam, expertQueryRequest);
        if (expertReadingVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(expertReadingVOS);
        return pageParam;
    }

    @Override
    public Page<ExpertReadingVO> getQueryByMyTeacher(Page<ExpertReadingVO> pageParam, ExpertQueryByMyRequest examQueryByMyRequest, Long teacherId) {
        // 自定义分页查询
        List<ExpertReadingVO> expertReadingVOS = expertReadingMapper.getQueryByMyTeacher(pageParam, examQueryByMyRequest, teacherId);
        if (expertReadingVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(expertReadingVOS);
        return pageParam;
    }

    @Override
    public Page<ExpertReadingVO> getQueryByMyStudent(Page<ExpertReadingVO> pageParam, ExpertQueryByMyRequest examQueryByMyRequest, Long userId) {
        // 自定义分页查询
        List<ExpertReadingVO> expertReadingVOS = expertReadingMapper.getQueryByMyStudent(pageParam, examQueryByMyRequest, userId);
        if (expertReadingVOS == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(expertReadingVOS);
        return pageParam;
    }
}




